﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBBase;

namespace Business
{
    public partial class photowaijian : Form
    {
        public photowaijian(string slsh,string hphm,string hpzl)
        {
            InitializeComponent();
            shphm = hphm;
            shpzl=hpzl;

            Query mquery = new Query();
            string sql;
            sql = string.Format(@"SELECT * FROM Detects_SJA where DET_LSH ='{0}'", slsh);
            slsh1 = mquery.GetDBString(sql, "DET_LSHZJ");

            getVINdata(slsh1, "WGXM_VIN", pictureBox1);
            getVINdata(slsh1, "WGXM_Q", pic_hgz);
            getVINdata(slsh1, "WGXM_H", pic_xsz);
            getVINdata(slsh1, "WGXM_DP", pic_wqd);


            string  ilsh=chaxunjilu(shphm, shpzl);
            if (ilsh.Length > 0)
            {
                 getVINdata(ilsh, "WGXM_VIN", pic_LS_VIN);
                 getVINdata(ilsh, "WGXM_Q", pic_LS_Q45);
                 getVINdata(ilsh, "WGXM_H", pic_LS_H45);

            }
            else
            {
                MessageBox.Show("无历史记录");
            }
        }

        private void photowaijian_Load(object sender, EventArgs e)
        {

        }
         public string slsh1;
        public string shphm;
        public string shpzl;
        
        public void getVINdata(string lsh,string szd,PictureBox pic)
        {
            Query mquery = new Query();
            string sql;
            sql = string.Format(@"Select * from WJXM Where WGXM_jylsh='{0}'", lsh);
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                byte[] content;
                if (dt.Rows[0][szd].ToString().Length > 10)
                {
                    content = (byte[])dt.Rows[0][szd];
                    if (content.Length > 10)
                    {
                        string base64 = Convert.ToBase64String(content);
                        //流数据写到控件上
                        System.IO.MemoryStream ms = new System.IO.MemoryStream(content);
                        //通过流对象建立Bitmap
                        System.Drawing.Bitmap bmp = new Bitmap(ms);
                        //this.pictureIC.Image = bmp;
                        Point ptLoction = new Point(bmp.Size);
                        if (ptLoction.X > pictureBox1.Size.Width || ptLoction.Y > pictureBox1.Size.Height)
                        {
                            //圖像框的停靠方式   
                            //圖像充滿圖像框，並且圖像維持比例   
                            pic.SizeMode = PictureBoxSizeMode.Zoom;
                        }
                        else
                        {
                            //圖像在圖像框置中   
                            pic.SizeMode = PictureBoxSizeMode.CenterImage;
                        }
                        pic.Image = bmp;
                    }
                }
            }
        }


        public string  chaxunjilu(string hphm,string hpzl)
        {
            Query mquery = new Query();
            string sql;
            sql = string.Format(@"Select  Detects_SJA.DET_LSH,Detects_SJA.DET_LSHZJ,AUTO.AT_HPHM,AUTO.AT_HPZL,Detects_SJA.DET_JCLB,Detects_SJA.DET_JYCS,Detects_SJA.DETECT_ID from AUTO,Detects_SJA Where AUTO.AT_ID=Detects_SJA.AT_ID ");
            sql = sql + string.Format(@" and AUTO.AT_HPHM='{0}' and AUTO.AT_HPZL='{1}' ", hphm, hpzl);
            sql = sql + " order by Detects_SJA.DETECT_ID  ";
       
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 1)
            {
                return dt.Rows[0]["DET_LSHZJ"].ToString().Trim();
            }
            else
            {
                return "";
            }
 
        }

        private void pic_wqd_DoubleClick(object sender, EventArgs e)
        {
            photoform f = new photoform();
            f.pictureBox1.Image = pic_wqd.Image;
            f.ShowDialog();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }
    }
}
